package com.yoo.ons.adapter

import android.content.Context
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.yoo.chat.kit.picture.config.PictureConfig
import com.yoo.ons.R
import com.yoo.ons.databinding.ItemPersonAlbumBinding
import com.yoo.ons.databinding.LayoutPictureAddBinding
import com.yoo.ons.function.album.viewmodel.PersonAlbumAddViewHolder
import com.yoo.ons.function.album.viewmodel.PersonAlbumViewViewHolder
import com.yoo.ons.model.PictureManagerModel
import com.yoo.ons.util.inflate

class PersonAlbumAdapter(var context: Context) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
    private var dataList = arrayListOf<PictureManagerModel>()
    override fun getItemViewType(position: Int): Int {
        return if (position == 0) {
            PictureConfig.TYPE_CAMERA
        } else {
            PictureConfig.TYPE_PICTURE
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
        return  if (viewType == PictureConfig.TYPE_CAMERA) {
            PersonAlbumAddViewHolder(LayoutPictureAddBinding.bind(parent.inflate(R.layout.layout_picture_add)))
        } else {
            PersonAlbumViewViewHolder(ItemPersonAlbumBinding.bind(parent.inflate(R.layout.item_person_album)))
        }
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        when(holder){
            is PersonAlbumAddViewHolder ->{
                holder.bind(dataList[position])
            }
            is PersonAlbumViewViewHolder ->{
                holder.bind(dataList[position],position)
            }
        }
    }

    fun setDataList(data: ArrayList<PictureManagerModel>){
        this.dataList = data
        notifyDataSetChanged()
    }
    fun getDataList(): ArrayList<PictureManagerModel> {
        return dataList
    }

    fun addAll(data: ArrayList<PictureManagerModel>) {
        dataList.addAll(data)
        notifyDataSetChanged()
    }


}